import http from 'wechat-http'

http.baseURL = 'https://slwl-api.itheima.net'

http.intercept.request = (options) => {
    const defaultHeader = {}
    defaultHeader.Authorization = 'Bearer ' + getApp().getToken()
    options.header = Object.assign({}, defaultHeader, options.header)
    return options
}
http.intercept.response = async ({data, config}) => {
    if (data.code === 401) {
        getApp().delToken()
        wx.redirectTo('/pages/login/login')
    }
    return data
}

wx.$http = http
export default http
